package h_10_21;

/**
 * 2379. 得到 K 个黑块的最少涂色次数
 * https://leetcode.cn/problems/minimum-recolors-to-get-k-consecutive-black-blocks/submissions/672465403/
 */
public class Main2 {
    public int minimumRecolors(String blocks, int k) {
        char[] ch = blocks.toCharArray();
        int n = blocks.length();
        int ret = Integer.MAX_VALUE;
        int sum = 0;
        for(int i = 0;i < n;i++) {
            if(ch[i] == 'W') {
                // 记录
                sum++;
            }

            // 判断
            if(i < k - 1) {
                continue;
            }

            // 更新，出窗口
            ret = Math.min(ret,sum);

            // 出
            if(ch[i - k + 1] == 'W') {
                sum--;
            }
        }
        return ret;
    }
}
